import axios from "axios";
import Cookies from 'js-cookie';

// 创建 axios 实例
//正式
const baseURL = 'https://small.yaqxj.com.cn/yaqxfw/'

// 石
// const baseURL = 'http://56c45338.r1.cpolar.top/yaqxfw'
// const baseURL = 'http://7f776790.r1.cpolar.top/yaqxfw'

//龚
// const baseURL = 'https://95ca582mt780.vicp.fun/yaqxfw'

// 胡
// const baseURL = 'https://816i9307t1.vicp.fun/yaqxfw'


const Request = axios.create({
    baseURL,
    timeout: 10000,
    headers: {
        "Content-Type": "application/json; charset=utf-8"
    },
});

// 请求拦截器
Request.interceptors.request.use(
    function (config) {
        const token = Cookies.get("token");// 从 cookie 中获取 token
        if (token) {
            config.headers["token"] = `Bearer ${token}`;

        }
        return config;
    },
    function (error) {
        return Promise.reject(error);
    }
);

// 响应拦截器
Request.interceptors.response.use(
    function (response) {
        return response;
    },
    function (error) {
        return Promise.reject(error);
    }
);

export default Request;
export { baseURL };
